//
//  UINavigationController+Ext.m
//  ICEubLib
//
//  Created by wujianrong on 16/4/11.
//  Copyright © 2016年 wanda. All rights reserved.
//

#import "UINavigationController+IceNavigator.h"

@implementation UINavigationController(IceNavigator)

-(void)ICEPresentViewController:(UIViewController *)viewControllerToPresent
{
    [self ICEPresentViewController:viewControllerToPresent animated:YES];
}

-(void)ICEPresentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)animated
{
    if (viewControllerToPresent == nil) {
        return;
    }
    if (animated) {
        CATransition* transition = [CATransition animation];
        transition.type = kCATransitionMoveIn;
        transition.subtype = kCATransitionFromTop;
        [self.view.layer addAnimation:transition forKey:kCATransition];
    }
    
    [self pushViewController:viewControllerToPresent animated:NO];
}

-(void)ICEDismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
{
    if (flag) {
        CATransition* transition = [CATransition animation];
        transition.type = kCATransitionReveal;
        transition.subtype = kCATransitionFromBottom;
        [self.view.layer addAnimation:transition forKey:kCATransition];
    }
    
    [self popViewControllerAnimated:NO];
}

-(void)ICEDismissViewController
{
    [self ICEDismissViewControllerAnimated:YES completion:nil];
}

-(void)ICEDismissToRootViewController
{
    
    CATransition* transition = [CATransition animation];
    transition.type = kCATransitionReveal;
    transition.subtype = kCATransitionFromBottom;
    [self.view.layer addAnimation:transition forKey:kCATransition];
    
    [self popToRootViewControllerAnimated:NO];
}

-(void)ICEDismissToViewController:(UIViewController*)vc
{
    
    CATransition* transition = [CATransition animation];
    transition.type = kCATransitionReveal;
    transition.subtype = kCATransitionFromBottom;
    [self.view.layer addAnimation:transition forKey:kCATransition];
    
    [self popToViewController:vc animated:NO];
}
@end
